import React from 'react'
import { Route, Redirect, withRouter } from 'react-router-dom'
import { inject, observer } from 'mobx-react';

//1.登陆权限
//2.登陆后的页面权限

@inject('baseStore')
@observer
class AuthRoute extends React.Component {


    render() {
        const { component: Component, ...rest } = this.props
        //token存在的表象
        let isLogged = (sessionStorage.getItem("token") || '').length > 0;

        isLogged = true;

        if (!isLogged) {
            //给个提示，延时跳转登陆页
            var that = this;
            that.props.history.push('/login');
        }



        return (
            <Route {...rest} render={props => {
                return isLogged
                    ? <Component {...props} />
                    : <Redirect to="/login" />
            }} />
        )
    }
}

export default withRouter(AuthRoute)